package com.why.rpc.core.common.loadbalance;

import com.alibaba.nacos.api.naming.pojo.Instance;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Random;

/**
 * @program: whyrpcframework
 * @description:
 * @author: @why
 * @create: 2021-03-14 10:05
 **/
@Slf4j
public class RandomLoadBalancer implements LoadBalancer{
    @Override
    public Instance selectInstance(List<Instance> instances) {
        log.info("使用随机的负载均衡策略选择服务提供者");
        int i = new Random().nextInt(instances.size());
        return  instances.get(i);
    }
}
